import play

class Main(play.Controller):

    def _before(self):
        if not self.session.has_key('user'):
            return self.redirect(Authentication.login)

    def index_html(self, name=None):
        return self.render('index.html', {'name': name})


class Authentication(play.Controller):

    def login(self):
        return self.render('login.html')

    def do_login(self, user):
        self.session['user'] = user
        return self.redirect(Main.index_html)

    def logout(self):
        self.session.clear()
        self.flash['message'] = 'You are now disconnected'
        return self.redirect(Authentication.login)
